<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>发货管理</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"
          th:href="@{/resource/css/font-awesome.min.css?v=4.4.0}"/>
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <!--checkbox-->
    <link href="../../resource/hotui/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
          th:href="@{/resource/hotui/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css}"
          rel="stylesheet"/>

    <link href="../../resource/css/style.min.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style.min.css?v=4.0.0}"/>
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get"
          th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${page.pageIndex}" name="pageIndex"/>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="userKey">用户：</label>
                                <input type="text" class="form-control input-sm mb10" id="userKey"
                                       th:value="*{userKey}" name="userKey" placeholder="用户名/交易号/姓名"
                                       style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="minNum">最低手数：</label>
                                <input type="text" class="form-control input-sm mb10" id="minNum"
                                       th:value="*{minNum}" name="minNum" placeholder="最低手数"
                                       style="width: 156px;"/>
                            </div>
                            <p style="height: 8px"></p>
                            <div class="form-group m-r-sm">
                                <button type="button" onclick="listHandler.search(1)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                </button>
                                <button type="button" onclick="listHandler.searchAll()"
                                        class="btn btn-primary btn-sm m-b-none">显示全部
                                </button>
                            </div>
                            <div class="form-group m-r-sm" style="float: right;">
                                <button type="button" onclick="listHandler.exportExcel()"
                                        class="btn btn-primary btn-sm m-b-none">批量导出
                                </button>
                            </div>
                            <div class="form-group m-r-sm" style="float: right;">
                                <button type="button" onclick="listHandler.showImportModal()"
                                        class="btn btn-primary btn-sm m-b-none">批量发货
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="ibox-content p-xxs no-top-border">

                    <div class="panel-body">
                        <table class="table table-bordered table-hover table-center">
                            <thead>
                            <tr>
                                <th style="text-align: center;">
                                    <div class="checkbox checkbox-default m-b-none m-t-none"
                                         style="display: inline-block;">
                                        <input style="margin-top: 0px; cursor: pointer;" type="checkbox" id="chkAll"/>
                                        <label for="chkAll"></label>
                                    </div>
                                </th>
                                <th>用户名</th>
                                <th>交易号</th>
                                <th>姓名</th>
                                <th>当前手数</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <tr th:each="item:${page.list}">
                                <td style="text-align: center">
                                    <div class="checkbox checkbox-default m-b-none m-t-none"
                                         style="display: inline-block;">
                                        <input th:id="${'chkUserId_'+item.userId}"
                                               style="margin-top: 0px; cursor: pointer;" type="checkbox"
                                               name="chkUserId" th:value="${item.userId}" value="560946"/>
                                        <label th:for="${'chkUserId_'+item.userId}"></label>
                                    </div>
                                </td>
                                <td th:text="${item.username}"></td>
                                <td th:text="${item.account}"></td>
                                <td th:text="${item.getRealName()}"></td>
                                <td th:text="${item.num}"></td>
                                <td>
                                    <a th:href="|javascript:listHandler.orderList(${item.userId},'${item.username}')|"
                                       href="javascript:listHandler.orderList(1,'')">订单明细</a>
                                </td>

                            </tr>
                            </tbody>
                        </table>
                        <p style="float: left; margin: 20px 0;">
                            共<span th:text="${page.totalPages}"></span>条记录，当前第<span th:text="${page.pageIndex}"></span>/<span
                                th:text="${page.totalPages==0?1:page.totalPages}"></span>，每页20条记录
                        </p>
                        <ul style="float: right;" class="pagination pagination-split">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="import_deliver_modal" style="display: none;">
    <div class="form-horizontal" style="width: 479px;height: 100px">
        <div class="form-group">
            <label class="col-sm-4 control-label">*选择文件：</label>
            <div class="col-sm-8">
                <input type="file" id="excelFile" name="excelFile" class="form-control input-sm"/>
            </div>
        </div>
    </div>
</div>
<!--基础框架js-->
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js(123123)}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"></script>

<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="../../resource/hotui/js/plugins/ajaxfileupload.js"
        th:src="@{/resource/hotui/js/plugins/ajaxfileupload.js}"></script>

<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${page.pageIndex}]]*/  1;
    const totalPages = /*[[${page.totalPages}]]*/  1;
    const pageUri = /*[[@{/order/retail/deliver/list}]]*/  "";
    const exportUri = /*[[@{/order/retail/deliver/export}]]*/  "";
    const importUri = /*[[@{/order/retail/deliver/batchDeliver/import}]]*/  "";
    const orderListUri = /*[[@{/order/retail/deliver/orderList}]]*/  "";
</script>
<script>
    var importModal = $("#import_deliver_modal").modal("批量导入发货", function () {
        hot.fileUpload(importUri, "excelFile", null, function (apiResult) {
            if (apiResult.resultCode === 2000) {
                hot.tip.success("批量导入发货成功", function () {
                    window.location.reload();
                });
            } else {
                hot.tip.error("发货失败--" + apiResult.resultMsg);
            }
        });
    });

    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            listHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                $(".searchBtn").trigger("click");
            }
        });

        $("#chkAll").change(function () {
            if ($(this).prop("checked")) {
                $("input[name=chkUserId]").prop('checked', 'checked');
            } else {
                $("input[name=chkUserId]").removeAttr("checked");
            }
        })
    });

    var listHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        exportExcel: function () {
            let userIds = "";
            $("input[name=chkUserId]:checked").each(function () {
                userIds += $(this).val() + ",";
            });
            if (userIds.length === 0) {
                alert("请勾选要导出的用户订单");
                return;
            }
            userIds = userIds.substring(0, userIds.length - 1);
            window.open(exportUri + "?userIds=" + userIds);
        },
        showImportModal: function () {
            importModal.show();
        },
        orderList: function (userId, username) {
            hot.iframeModal(orderListUri + "/" + userId, window.innerWidth * 0.8 + "px", window.innerHeight * 0.85 + "px", username + '的待发货订单');
        }
    }
</script>
</body>
</html>
